import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [{
    path: '/',
    redirect: '/login'
  },
  {
    path: '/home',
    redirect: '/home/info'
  },
  {
    path: '/login',
    component: () =>
      import ('../views/AdminLogin.vue'),
  },
  {
    path: '/register',
    component: () =>
      import ('../views/UserRegister.vue'),
  },
  {
    path: '/home',
    component: () =>
      import ('../layout/ContainerView.vue'),
    children: [ // 嵌套路由
      {
        path: '/home/info',
        component: () =>
          import ('../views/HomView.vue'),
      },
      // 商品列表
      {
        path: '/home/goods',
        component: () =>
          import ('../views/listAllNow.vue'),
      },
      // 订单列表
      {
        path: '/home/orders',
        component: () =>
          import ('../views/listMyOrder.vue'),
      },
      {
        path: '/home/user',
        component: () =>
          import ('../views/UserView.vue')
      },
      {
        path: '/home/role',
        component: () =>
          import ('../views/RoleView.vue')
      },
      {
        path: '/home/permission',
        component: () =>
          import ('../views/PermissionView.vue')
      },
      {
        path: '/home/addUser',
        component: () =>
          import ('../views/AddUser.vue')
      },
      {
        path: '/home/editUser',
        component: () =>
          import ('../views/EditUser.vue')
      },
      {
        path: '/home/addRole',
        component: () =>
          import ('../views/AddRole.vue')
      },
      {
        path: '/home/editRole',
        component: () =>
          import ('../views/EditRole.vue')
      },
      {
        path: '/home/addPermission',
        component: () =>
          import ('../views/AddPermission.vue')
      },
      {
        path: '/home/editPermission',
        component: () =>
          import ('../views/EditPermission.vue')
      },
      {
        path: '/home/productList',
        component: () =>
          import ('../views/ProductList.vue')
      },
      {
        path: '/home/sellerOrders',
        component: () =>
          import ('../views/listSellerOrder.vue')
      },
      {
        path: '/home/audit',
        component: () =>
          import ('../views/ProductAudit.vue')
      }
    ]
  },

  {
    path: '/404',
    component: () =>
      import ('../views/404View.vue')
  },
  {
    path: '/*',
    redirect: '/404'
  }
]

// 防止连续点击多次路由报错
let routerPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router